/**
 * 
 */
package testcases;

import com.trentech.billcalc.BillCalc;
import com.trentech.billcalc.FinanceManager;
import com.trentech.billcalc.Resident;
import com.trentech.billcalc.event.PayEvent;
import static org.junit.Assert.assertEquals;


/**
 * @author marieputri
 *
 */
public class PayTest 
{
    public static void testPay() throws Exception
    {
        FinanceManager fm = new FinanceManager();
        
        // Start new file
        // MainTest.startFile();
        // assertEquals(0, fm.getResidents().size());
        // assertEquals(0, fm.getEvents().size());
        
        // Arrive : Marie Putri,day-10 <as the owner of the apartment>
        EventData.SaveEvent(fm, EventData.ListArrive.get(0));
        // Arrive : Jessa,day-2 <as one of residents>
        EventData.SaveEvent(fm, EventData.ListArrive.get(2));     
        assertEquals(2, fm.getResidents().size());
        
        // SetupBill : Gass Bill,-8
        EventData.SaveEvent(fm, EventData.ListSetupBill.get(0));
        
        // OptOut-OptIn : Jessa doesnt pay for Gass Bill from arrival date until 5
        EventData.SaveEvent(fm, EventData.ListOptOut.get(0));
        EventData.SaveEvent(fm, EventData.ListOptIn.get(0));
        
        // Bill : Gass Bill,1,12000
        // Bill has not been charged until next bill comes
        EventData.SaveEvent(fm, EventData.ListBill.get(0));
        
        // Bill : Gass Bill,6,15000
        // Charged Bill : 2400, Days : 5 (Jessa doesnt pay from -2~5, but from 6~11)
        // Gass Bill : Marie Putri 10800, Jessa 1200
        EventData.SaveEvent(fm, EventData.ListBill.get(1));
        assertEquals(10800, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(1200, fm.getTotalOwing(fm.findResident("Jessa")));
        
        // Pay : Marie Putri pays 10000 to Jessa
        EventData.SaveEvent(fm, EventData.ListPay.get(0));
        assertEquals(800, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(11200, fm.getTotalOwing(fm.findResident("Jessa")));

        // Pay : Jessa pays 12000 to Gass Bill
        EventData.SaveEvent(fm, EventData.ListPay.get(1));
        assertEquals(800, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(-800, fm.getTotalOwing(fm.findResident("Jessa")));

        // Bill : Telephone Bill arrives on 10 for 12000
        // Charged Bill : 600, Days : 20 (Jessa doesnt pay from -9~-3, but from -2~10)
        // Telephone Bill : Marie Putri 8100, Jessa 3900
        EventData.SaveEvent(fm, EventData.ListBill.get(2));
        assertEquals(8900, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(3100, fm.getTotalOwing(fm.findResident("Jessa")));

        // Arrive : Nexia arrives on 5
        // Gass Bill <2400> on 2-3 (Marie Putri), on 4-5 (Marie Putri and Nexia), 6 (all 3)
        // Telephone Bill <600> on -9~-3 (Marie Putri), on -2~3 (Marie Putri and Jessa), 4~10 (all 3)
        // Nexia should pay Telephone Bill (1400) and Gass Bill (3200)
        EventData.SaveEvent(fm, EventData.ListArrive.get(4));
        assertEquals(5400, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(2000, fm.getTotalOwing(fm.findResident("Jessa")));
        assertEquals(4600, fm.getTotalOwing(fm.findResident("Nexia")));
        
        // Vacation : Marie Putri starts vacation on 6 and stops on 12
        // Gass Bill <2400> on 2-3 (Marie Putri), on 4-5 (Marie Putri and Nexia), 6 (all 3) --> because fixed cost
        // Telephone Bill <600> on -9~-3 (Marie Putri), on -2~3 (Marie Putri and Jessa), 4~5 (all 3), 6~10 (Jessa and Nexia)
        EventData.SaveEvent(fm, EventData.ListStartVacation.get(0));
        EventData.SaveEvent(fm, EventData.ListStopVacation.get(0));
        assertEquals(4400, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(2500, fm.getTotalOwing(fm.findResident("Jessa")));
        assertEquals(5100, fm.getTotalOwing(fm.findResident("Nexia")));
        
        // Bill : Gass Bill arrives on 11 for 9000
        // Gass Bill <3000> on 7-11 (all 3)
        EventData.SaveEvent(fm, EventData.ListBill.get(3));
        assertEquals(9400, fm.getTotalOwing(fm.findResident("Marie Putri")));
        assertEquals(7500, fm.getTotalOwing(fm.findResident("Jessa")));
        assertEquals(10100, fm.getTotalOwing(fm.findResident("Nexia")));
        
        // Pay : Nexia pays Telephone Bill 12000 on 11
        EventData.SaveEvent(fm, EventData.ListPay.get(2));
        assertEquals(-1900, fm.getTotalOwing(fm.findResident("Nexia")));
        
        //BillCalc.main(null);*/
    }
    
}
